class Solution(object):
    def maxSizeSlices(self, slices):
        n = len(slices)
        target = n // 3
        DP = [[0] * (target + 1) for _ in range(n - 1)]
        for i in range(n - 1):
            if i == 0:
                DP[i][1] = slices[i]
            else:
                if i == 1:
                    DP[i][1] = max(slices[i], slices[i - 1])
                else:
                    for k in range(1, target + 1):
                        DP[i][k] = max(DP[i - 1][k], DP[i][k], DP[i - 2][k - 1] + slices[i])
        max_val = max([DP[i][target] for i in range(n - 1)])
        slices = slices[1:]
        DP = [[0] * (target + 1) for _ in range(n - 1)]
        for i in range(n - 1):
            if i == 0:
                DP[i][1] = slices[i]
            else:
                if i == 1:
                    DP[i][1] = max(slices[i], slices[i - 1])
                else:
                    for k in range(1, target + 1):
                        DP[i][k] = max(DP[i - 1][k], DP[i][k], DP[i - 2][k - 1] + slices[i])
        max_val = max(max([DP[i][target] for i in range(n - 1)]), max_val)
        return max_val

data = Solution()
slices = [1, 2, 3, 4, 5, 6]
print(data.maxSizeSlices(slices))
